package com.sfac.dao;

import com.sfac.test.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * CountryDao
 */
@Repository
@Mapper
public interface CountryDao {

	@Select("select * from test_country where country_id = #{countryId}")
	@Results(id = "countryResults", value = {
			@Result(property="countryId", column = "country_id"),
			@Result(property = "cities",
					column = "country_id",
					javaType = List.class,
					many = @Many(select = "com.sfac.springBoot.modules.test.dao.CityDao.getCitiesByCountryId"))
	})
	Country getCountryByCountryId(int countryId);

	@Select("select * from test_country where country_name = #{countryName} limit 1")
	@ResultMap(value={"countryResults"})
	Country getCountryByCountryName(String countryName);
}
